/*
 *  Copyright 2005 Blandware (http://www.blandware.com)
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */
package com.blandware.atleap.model.forum;

import com.blandware.atleap.model.core.BaseObject;
import com.blandware.atleap.model.core.User;

import java.util.Date;

/**
 * <p>Represents an email subscription which allows to 'track' forum or topic.
 * </p>
 * <p><a href="ForumSubscription.java.html"><i>View source</i></a></p>
 *
 * @author Roman Puchkovskiy <a href="mailto:roman.puchkovskiy@blandware.com">
 *         &lt;roman.puchkovskiy@blandware.com&gt;</a>
 * @version $Revision: 1.3 $ $Date: 2006/10/03 11:26:32 $
 * @struts.form include-all="false" extends="BaseForm"
 * @hibernate.class table="`al_forum_subscription`" lazy="false"
 * @hibernate.cache usage="read-write"
 */
public class ForumSubscription extends BaseObject {

    /**
     * Subscription ID
     */
    protected Long id = null;

    /**
     * Forum to which user subscribed
     */
    protected Forum forum = null;

    /**
     * Topic to which user subscribed
     */
    protected Topic topic = null;

    /**
     * User that subscribed
     */
    protected User user = null;

    /**
     * Email of user that subscribed
     */
    protected String email = null;

    /**
     * Token
     */
    protected String token = null;

    /**
     * Whether subscription is activated
     */
    protected Boolean activated = null;

    /**
     * Date when user subscribed
     */
    protected Date date = null;

    /**
     * Creates a forum subscription instance.
     */
    public ForumSubscription() {
    }

    /**
     * Creates a forum subscription instance initializing forum, topic, user
     * and email.
     *
     * @param forum forum
     * @param topic topic
     * @param user user
     * @param email email
     */
    public ForumSubscription(Forum forum, Topic topic, User user, String email) {
        this.forum = forum;
        this.topic = topic;
        this.user = user;
        this.email = email;
    }

    /**
     * Returns subscription ID.
     *
     * @return ID
     * @struts.form-field
	 * @hibernate.id column="`id`"
	 * generator-class="increment" unsaved-value="null"
     */
    public Long getId() {
        return id;
    }

    /**
     * Sets subscription ID.
     *
     * @param id ID to set
     */
    public void setId(Long id) {
        this.id = id;
    }

    /**
     * Returns forum to which user subscribed.
     *
     * @return forum
     * @hibernate.many-to-one column="`forum_id`" not-null="false"
     * outer-join="false" lazy="false"
     */
    public Forum getForum() {
        return forum;
    }

    /**
     * Sets forum to which user subscribed.
     *
     * @param forum forum to set
     */
    public void setForum(Forum forum) {
        this.forum = forum;
    }

    /**
     * Returns topic to which user subscribed.
     *
     * @return topic
     * @hibernate.many-to-one column="`topic_id`" not-null="false"
     * outer-join="false" lazy="false"
     */
    public Topic getTopic() {
        return topic;
    }

    /**
     * Sets topic to which user subscribed.
     *
     * @param topic topic to set
     */
    public void setTopic(Topic topic) {
        this.topic = topic;
    }

    /**
     * Returns user which subscribed.
     *
     * @return user
     * @hibernate.many-to-one column="`username`" not-null="false"
     * outer-join="false" lazy="false"
     */
    public User getUser() {
        return user;
    }

    /**
     * Sets user.
     *
     * @param user user to set
     */
    public void setUser(User user) {
        this.user = user;
    }

    /**
     * Returns email of user who subscribed.
     *
     * @return email
     * @struts.form-field
     * @struts.validator type="required"
	 * @struts.validator type="email"
	 * @struts.validator-args arg0resource="forum.subscription.form.email"
	 * @hibernate.property
	 * @hibernate.column name="`email`" not-null="false" unique="false"
     * length="252"
     */
    public String getEmail() {
        return email;
    }

    /**
     * Sets email of user who subscribed.
     *
     * @param email email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     * Returns a token.
     *
     * @return token
     * @struts.form-field
	 * @hibernate.property
	 * @hibernate.column name="`token`" not-null="false" unique="false"
     * length="252"
     */
    public String getToken() {
        return token;
    }

    /**
     * Sets a token.
     *
     * @param token token to set
     */
    public void setToken(String token) {
        this.token = token;
    }

    /**
     * Returns whether this subscription is activated.
     *
     * @return whether this subscription is activated
     * @struts.form-field
	 * @hibernate.property column="`activated`" not-null="true"
     * type="true_false"
     */
    public Boolean getActivated() {
        return activated;
    }

    /**
     * Sets whether this subscription is activated.
     *
     * @param activated whether this subscription is activated
     */
    public void setActivated(Boolean activated) {
        this.activated = activated;
    }

    /**
     * Returns date when user subscribed.
     *
     * @return date
     * @hibernate.property
	 * @hibernate.column name="`date`" not-null="false" unique="false"
     */
    public Date getDate() {
        return date;
    }

    /**
     * Sets date when user subscribed.
     *
     * @param date date to set
     */
    public void setDate(Date date) {
        this.date = date;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof ForumSubscription)) return false;

        final ForumSubscription forumSubscription = (ForumSubscription) o;

        if (email != null ? !email.equals(forumSubscription.email) : forumSubscription.email != null) return false;
        if (forum != null ? !forum.equals(forumSubscription.forum) : forumSubscription.forum != null) return false;
        if (topic != null ? !topic.equals(forumSubscription.topic) : forumSubscription.topic != null) return false;
        if (user != null ? !user.equals(forumSubscription.user) : forumSubscription.user != null) return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = (forum != null ? forum.hashCode() : 0);
        result = 29 * result + (topic != null ? topic.hashCode() : 0);
        result = 29 * result + (user != null ? user.hashCode() : 0);
        result = 29 * result + (email != null ? email.hashCode() : 0);
        return result;
    }
}
